package com.huyn.baseframework.dynamicload;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.view.LayoutInflater;

import com.ryg.dynamicload.internal.DLPluginPackage;

/**
 * Created by huyaonan on 16/10/10.
 */
public class DLContextWrapper extends ContextWrapper {



    private DLPluginPackage pluginPackage;

    public DLContextWrapper(Context base, DLPluginPackage pluginPackage) {
        super(base);
        this.pluginPackage = pluginPackage;
    }

    @Override
    public Resources getResources() {
        return pluginPackage.resources;
    }

    @Override
    public AssetManager getAssets() {
        return pluginPackage.assetManager;
    }

    @Override
    public ClassLoader getClassLoader() {
        return pluginPackage.classLoader;
    }

    @Override
    public String getPackageName() {
        return pluginPackage.packageName;
    }

    public Class loadClass(String clazzName) throws ClassNotFoundException {
        if(clazzName.startsWith("android"))
            return getBaseContext().getClassLoader().loadClass(clazzName);
        return getClassLoader().loadClass(clazzName);
    }

}
